using System.Collections.Generic;
using UnityEngine;
using Voodoo.Pattern;

public class Map : MonoBehaviour
{
	private List<Transform> blocks = new List<Transform>();

	private List<Vector3> blocksPoses = new List<Vector3>();

	public List<Transform> Blocks => blocks;

	public void Processs()
	{
		blocks.Clear();
		for (int i = 0; i < base.transform.childCount; i++)
		{
			if (base.transform.GetChild(i).tag == "Finish")
			{
				Transform child = base.transform.GetChild(i);
				if (Random.Range(0, 10) == 4)
				{
					child.position += new Vector3(0f, 0f, Random.Range(-0.02f, 0.02f));
				}
				child.localScale = Vector3.one * Random.Range(0.9f, 1.3f);
				child.localEulerAngles = new Vector3(Random.Range(0, 14), Random.Range(0, 14), Random.Range(0, 14));
				if (!SingletonMB<BonusLevelManager>.Instance.IsBonusLevelActive)
				{
					blocks.Add(child);
					blocksPoses.Add(child.localPosition);
				}
			}
		}
		Object.FindObjectOfType<Progress>().SetMaxCount(blocks.Count);
		GetComponent<GemSpawner>().SpawnGems(blocks);
		GetComponent<GemSpawner>().SpawnKey(blocks);
	}

	private void x()
	{
		for (int i = 0; i < blocks.Count; i++)
		{
			blocks[i].localPosition = blocksPoses[i];
			blocks[i].tag = "Finish";
			blocks[i].gameObject.SetActive(value: true);
		}
	}

	public void ResetMap()
	{
		for (int i = 0; i < blocks.Count; i++)
		{
			blocks[i].localPosition = blocksPoses[i];
			blocks[i].tag = "Finish";
			blocks[i].gameObject.SetActive(value: true);
			blocks[i].transform.localEulerAngles = new Vector3(Random.Range(0, 12), Random.Range(0, 12), Random.Range(0, 12));
			if (blocks[i].TryGetComponent<Rigidbody>(out var component))
			{
				component.isKinematic = true;
			}
		}
		Object.FindObjectOfType<Progress>().SetMaxCount(blocks.Count);
		GetComponent<GemSpawner>().SpawnGems(blocks);
		GetComponent<GemSpawner>().SpawnKey(blocks);
	}
}
